using System;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Model;
using Me.Prettyprint.Cassandra.Model.Thrift;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Factory;
using Me.Prettyprint.Hector.Api.Mutation;
using Thrift;

namespace Me.Prettyprint.Cassandra.Service.Template
{
    /// <summary>
    /// Note: Java Hector uses Iterator<ColumnFamilyResult<?,?>>
    /// Since .Net and C# doesn't support wild card "?" in generics,
    /// we use K and N instead. ColumnFamilyResult in Java uses
    /// K and N, so I'm not sure exactly why wild card is used.
    /// I tried to keep it as close to ColumnFamilyResultIterator
    /// as practical, but it doesn't have remove.
    /// </summary>
    /// <typeparam name="K"></typeparam>
    /// <typeparam name="N"></typeparam>
    public class ColumnFamilyResultEnumerator<K, N>
	{
		public ColumnFamilyResultEnumerator()
		{
            IsStart = true;
		}
        public ColumnFamilyResultEnumerator(ColumnFamilyResult<K,N> res) : this()
        {
            Result = res;
        }
        public ColumnFamilyResult<K, N> Result
        {
            get;
            protected set;
        }
        protected bool IsStart
        {
            get;
            set;
        }
        public ColumnFamilyResultWrapper<K, N> ColumnFamilyResult
        {
            get
            {
                return ((ColumnFamilyResultWrapper<K, N>)Result);
            }
        }
        public ColumnFamilyResult<K,N> Current
        {
            get
            {
                if (IsStart)
                {
                    IsStart = false;
                    return Result;
                }
                else
                {
                    return (ColumnFamilyResult<K, N>)ColumnFamilyResult.Next();
                }
            }
        }
        public bool MoveNext()
        {
            bool retval = false;
            if (IsStart)
            {
                if (Result.HasResults || ColumnFamilyResult.HasNext())
                {
                    retval = true;
                }
            }
            else
            {
                retval = ColumnFamilyResult.HasNext();
            }
            return retval;
        }
        public void Reset()
        {
        }
        public void Dispose()
        {
        }
	}
}